package com.hzncc.flowable_diboot.excel.listener;

import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHolder;
import com.diboot.core.util.V;
import com.diboot.file.excel.listener.FixedHeadExcelListener;
import com.hzncc.flowable_diboot.entity.Customer;
import com.hzncc.flowable_diboot.excel.model.CustomerImportModel;
import com.hzncc.flowable_diboot.service.CustomerService;

import java.util.List;
import java.util.Map;

/**
* 客户 导入Listener定义
*
* @author MyName
* @version 1.0
* @date 2024-06-21
 * Copyright © MyCorp
*/
public class CustomerImportListener extends FixedHeadExcelListener<CustomerImportModel> {
    /**
    * 自定义校验规则
    *
    * @param dataModelList    待保存的数据
    * @param requestParams  请求参数
    */
    @Override
    protected void additionalValidate(List<CustomerImportModel> dataModelList, Map<String, Object> requestParams) {
        // 附加校验
    }

    /**
    * 保存数据
    *
    * @param dataModelList 待保存的数据
    * @param requestParams 请求参数
    */
    @Override
    public void saveData(List<CustomerImportModel> dataModelList, Map<String, Object> requestParams) {
        if (V.isEmpty(dataModelList)) {
            return;
        }
        List<Customer> entityList = BeanUtils.convertList(dataModelList, Customer.class);
        ContextHolder.getBean(CustomerService.class).createEntities(entityList);
    }
}
